package org.example.search.controller;

import org.example.core.utils.R;
import org.example.search.module.SkuEsModule;
import org.example.search.service.EsProductFrontService;
import org.example.search.vo.DefaultRespVo;
import org.example.search.vo.SearchParamVo;
import org.example.search.vo.SearchRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 小杰_cc
 * @version 1.0
 */
@RestController
@RequestMapping("/search/front")
public class EsProductFrontController {

    @Autowired
    private EsProductFrontService esProductFrontService;

    /**
     * 商品检索(GET请求中文乱码懒得解决改成POST)
     */
    @PostMapping("/list")
    public R<?> EsProductSearch(@RequestBody SearchParamVo searchParamVo){
        SearchRespVo vos = esProductFrontService.search(searchParamVo);
        return R.ok(vos);
    }

    /**
     * 猜你喜欢商品展示
     */
    @GetMapping("/like")
    public R<?> EsHomeLike(@RequestParam(defaultValue = "1") Integer pageNum){
        DefaultRespVo respVo = esProductFrontService.like(pageNum);
        return R.ok(respVo);
    }

    /**
     * 根据spu集合查询收藏的商品
     */
    @GetMapping("/collect")
    public R<List<SkuEsModule>> EsCollect(){
        List<SkuEsModule> skuEsModules = esProductFrontService.getEsCollectInfo();
        return R.ok(skuEsModules);
    }

    /**
     * 同类推荐
     */
    @GetMapping("/same/{spuId}/{categoryId}")
    public R<List<SkuEsModule>> EsSameCategory(@PathVariable("spuId") Long spuId, @PathVariable("categoryId") Long categoryId){
        List<SkuEsModule> skuEsModules = esProductFrontService.getSameCategorySku(spuId, categoryId);
        return R.ok(skuEsModules);
    }
}
